// subPages/pressure/index/index.js
var template = require('../../../template/template.js');
var util =  require('../../../utils/util.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pressureDataList:[{
      name: '收缩压 (高压)',
      value:'0',
      status:'',
      index : 1
    },{
      name: '舒张压 (低压)',
      value:'0',
      status:'',
      index: 2
    },{
      name: '心  率 (bpm)',
      value:'0',
      status:'',
      index: 3
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    template.pressureTabbar("tabBar", 0, this) //0表示第一个tabbar
  },

  //更新数据
  updateBtn:function(){
    var that = this
    wx.request({
      url: app.globalData.apiUrl +'/newone',
      data: {
        userId: app.globalData.userId
        // userId: '50009181542961462'
      },
      method: 'get',
      header: {
        'content-type': 'application/json' //默认值
      },
      success: function (res) {
        // console.log(res)
          if(res.data.code == '200'){
              that.pressureDataList(res.data.data)
          }else{
              util.showModal('提示','暂无测量数据，请重新测量')
              return;
          }
      },
      fail: function (res) {
        console.log("失败",res);
      }
    })
  },

  //处理数据
  pressureDataList:function(data){
    var that = this 
    var list = that.data.pressureDataList
    for(var i in list){
      if(list[i].index == 1)
      {
        list[i].value = data.height
        list[i].status = data.heighttype
      }
      if(list[i].index == 2)
      {
        list[i].value = data.low
        list[i].status = data.lowtype
      }
      if(list[i].index == 3)
      {
        list[i].value = data.heart
        list[i].status = data.hearttype
      }
    }
    that.setData({
      pressureDataList: list
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})